/* 修改数据存储的结构，把图片改存在一个数组里 images: []
* */
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')

const dataBaseDir = 'E:/code/electron/dream/src/data/'

const db = low(new FileSync(`${dataBaseDir}/movie.json`))

const movies = db.read()
    .get('movies')
    .value()

const newMovies = []

for (let movie of movies) {
    const newMovie = {
        name: '',
        year: 0,
        star: '',
        rootDir: '',
        images: [],
        dreamVideos: [],
    }
    Object.assign(newMovie, movie)
    newMovie.images.push(movie.cover)
    newMovie.images.push(...movie.img)

    delete newMovie.cover
    delete newMovie.img

    newMovie.dreamVideos = []

    for (let dreamVideo of movie.dreamVideos) {
        const newDreamVideo = {
            name: '',
            video: '',
            images: [],
        }
        Object.assign(newDreamVideo, dreamVideo)
        newDreamVideo.images.push(dreamVideo.cover)
        newDreamVideo.images.push(...dreamVideo.img)
        delete newDreamVideo.cover
        delete newDreamVideo.img
        newMovie.dreamVideos.push(newDreamVideo)
    }
    newMovies.push(newMovie)
}

// console.log(newMovies)
db.read()
    .set('movies', newMovies)
    .write()
